/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Client;
import java.net.InetAddress;
import java.net.Socket;
import java.io.ObjectOutputStream;
import Communication.C2ServerPacket;
/**
 *
 * @author cypek
 */
public class ClientController {


    private Client client;
    private boolean lockButtons;
    private Socket socket;
    private InetAddress destAddress;


    private void initSocket()
    {
        try{
            destAddress = InetAddress.getByName(this.getClient().getHost()); // Destination address
            int destPort = this.getClient().getPort();              // Destination port
            this.socket = new Socket(destAddress, destPort);
        }
        catch (Exception ex)
        {
            System.out.println("Blad podczas otwierania socekta");
        }
    }
    /**
     * Get the value of socket
     *
     * @return the value of socket
     */
    public Socket getSocket() {
        return socket;
    }


    /**
     * Set the value of socket
     *
     * @param socket new value of socket
     */
    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public void sendPacketToServer(int desireFloor, int desireDir,
                            int clientCurrentFloor)
    {
        C2ServerPacket packet = new C2ServerPacket(desireFloor, desireDir, clientCurrentFloor);
        try{
            ObjectOutputStream oos = new ObjectOutputStream(this.getSocket().getOutputStream());
            oos.writeObject(packet);
            oos.flush();
        }
        catch(Exception ex) {
            System.out.println("Blad podczas wysylania do serwera");
        }
    }

    /**
     * Get the value of lockButtons
     *
     * @return the value of lockButtons
     */
    public boolean isLockButtons() {
        return lockButtons;
    }

    /**
     * Set the value of lockButtons
     *
     * @param lockButtons new value of lockButtons
     */
    public void setLockButtons(boolean lockButtons) {
        this.lockButtons = lockButtons;
    }

    /**
     * Get the value of client
     *
     * @return the value of client
     */
    public Client getClient() {
        return client;
    }

    /**
     * Set the value of client
     *
     * @param client new value of client
     */
    public void setClient(Client client) {
        this.client = client;
    }


    public ClientController(Client client) {
        this.client = client;
        this.lockButtons = false;
        initSocket();
    }

    public void update()
    {
     
    }


}
